using System;
using System.Xml;

namespace OR.Reuse.Persistence
{
	/// <summary>
	/// Summary description for EntityBase.
	/// </summary>
	public abstract class EntityBase
	{
		protected EntityCollectionBase	mParentCollection;
		protected EntityBase			mParentEntity;

		public EntityCollectionBase ParentCollection
		{
			get
			{
				return ( mParentCollection );
			}
			set
			{
				mParentCollection = value;
			}
		}

		public EntityBase ParentEntity
		{
			get
			{
				return ( mParentEntity );
			}
			set
			{
				mParentEntity = value;
			}
		}

      public virtual XmlDocument SaveXmlDocument()
      {
         XmlDocument	v_oReturn	= new XmlDocument();

         v_oReturn.AppendChild( this.SaveXml( v_oReturn ) );

         return ( v_oReturn );
      }

      public virtual long Length
      {
         get
         {
            return ( this.GetLength() );
         }
      }

      public virtual long GetLength()
      {
         XmlDocument	v_oDocument = this.SaveXmlDocument();

         return ( v_oDocument.OuterXml.Length );
      }

		public virtual void LoadXml( XmlDocument pSource )
		{
			this.LoadXml( pSource.DocumentElement );
		}

		public virtual void LoadXml( string pFilename )
		{
			XmlDocument vDocument = new XmlDocument();

			vDocument.Load( pFilename );

			this.LoadXml( vDocument );
		}

      public abstract void LoadXml( XmlElement p_oSource );
      public abstract XmlElement SaveXml( XmlDocument p_docContext );
      
      public EntityBase()
		{
			//
			// TODO: Add constructor logic here
			//
		}
	}
}
